package com.fh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fh.vo.ContractVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fh.mapper.ContractMapper;
import com.fh.entity.Contract;
import com.fh.service.ContractService;
/**
@author huangp
@create 2021-04-07 20:08
*/
@Service
public class ContractServiceImpl extends BaseService implements ContractService{

    @Override
    public void add(Contract contract) {
        this.contractMapper.insert(contract);
    }

    @Override
    public void update(Contract contract) {
        QueryWrapper<Contract> update = new QueryWrapper<>();
        update.eq("contract_id",contract.getContractId());
        this.contractMapper.update(contract,update);
    }

    @Override
    public void delete(Integer contractId) {
        this.contractMapper.deleteById(contractId);
    }

    @Override
    public Contract getById(Integer contractId) {
        return this.contractMapper.selectById(contractId);
    }

    @Override
    public List<Contract> query(ContractVo vo) {
        QueryWrapper<Contract> query = new QueryWrapper<>();
        if(vo.getContractName()!=null && vo.getContractName()!=""){
            query.like("contract_name","%"+vo.getContractName()+"%");
        }
        List<Contract> contracts = this.contractMapper.selectList(query);
        return contracts;
    }
}
